{% extends "inventory/base.html" %}
{% load crispy_forms_tags %}

{% block title %}{{ form_title }}{% endblock %}

{% block content %}
<div class="container">
    <div class="row mb-4">
        <div class="col-12">
            <h1 class="h2">{{ form_title }}</h1>
            <p class="text-muted">{{ inventory_check.description }}</p>
        </div>
    </div>

    <div class="row mb-4">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h3 class="h5 mb-0">需要确认的差异项</h3>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table mb-0">
                            <thead class="table-light">
                                <tr>
                                    <th>商品名称</th>
                                    <th>条码</th>
                                    <th class="text-center">系统数量</th>
                                    <th class="text-center">实际数量</th>
                                    <th class="text-center">差异</th>
                                    <th>备注</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for item in items_with_discrepancy %}
                                <tr class="{% if item.difference < 0 %}table-danger{% else %}table-warning{% endif %}">
                                    <td>{{ item.product.name }}</td>
                                    <td><code>{{ item.product.barcode }}</code></td>
                                    <td class="text-center">{{ item.system_quantity }}</td>
                                    <td class="text-center">{{ item.actual_quantity }}</td>
                                    <td class="text-center">
                                        <span class="{% if item.difference > 0 %}text-success{% elif item.difference < 0 %}text-danger{% endif %}">
                                            {{ item.difference }}
                                        </span>
                                    </td>
                                    <td>{{ item.notes|default:"-" }}</td>
                                </tr>
                                {% empty %}
                                <tr>
                                    <td colspan="6" class="text-center py-4">没有盘点差异</td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card">
                <div class="card-header">
                    <h3 class="h5 mb-0">审核确认</h3>
                </div>
                <div class="card-body">
                    <form method="post">
                        {% csrf_token %}
                        {{ form|crispy }}
                        <div class="d-flex justify-content-between mt-4">
                            <a href="{% url 'inventory_check_detail' check_id=inventory_check.id %}" class="btn btn-outline-secondary">返回</a>
                            <button type="submit" class="btn btn-success">{{ submit_text }}</button>
                        </div>
                    </form>
                </div>
                <div class="card-footer">
                    <div class="small text-muted">
                        <p>
                            <i class="bi bi-info-circle"></i>
                            审核盘点后，将无法再修改盘点结果。如果选择调整库存，系统将自动根据实际盘点结果调整库存数量。
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %} 